package jp.sinya.threadlocal;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class Demo1 {
    @Test
    public void test1() {
        ThreadLocal<String> tl = new ThreadLocal<>();
        tl.set("hello");//存
        String s = tl.get();//取
        tl.remove();//删
        System.out.println(s);
    }
}

//ThreadLocal的理解
class MyTheard<T> {
    private Map<Thread, T> map = new HashMap<>();

    public void set(T data) {
        map.put(Thread.currentThread(), data);
    }

    public T get() {
        return map.get(Thread.currentThread());
    }

    public void remove() {
        map.remove(Thread.currentThread());
    }
}